from aiogram_dialog import DialogManager
from sqlalchemy.ext.asyncio import AsyncSession

from app.database.services.categories import get_category


async def sites_getter(
    db_session: AsyncSession, dialog_manager: DialogManager, **kwargs
):
    category_id: int = dialog_manager.dialog_data.get("category_id")

    if not category_id and dialog_manager.start_data:
        category_id: int = dialog_manager.start_data.get("category_id")

    category = await get_category(db_session, category_id, joined=True)
    sites = category.sites if category else []

    return {
        "sites": sites,
        "count": len(sites),
    }
